home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
local
/
genRSAKey.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
2KB
|
56 lines
<?php
/**
* RSA Key generation
* Generates RSA key used for javascript password encryption
*
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.0.0
*/
echo ">";
require_once 'Crypt/RSA.php';
require_once 'Crypt/RSA/Math/BCMath.php';
define('MATH_LIBRARY', 'BCMath');
$bcm= new Crypt_RSA_Math_BCMath;
$baseDir=str_replace('\\','/',dirname($_SERVER['SCRIPT_FILENAME']).'/../../');
if(file_exists($baseDir.'data/general.ini')) $config=parse_ini_file($baseDir.'data/general.ini');
if(isset($config['loginKeyLength'])) $keyLength=$config['loginKeyLength']; else $keyLength=384;
// Generate key
$key_pair = new Crypt_RSA_KeyPair($keyLength, MATH_LIBRARY, 'check_error',65537);
$public_key = $key_pair->getPublicKey();
$private_key = $key_pair->getPrivateKey();
$key_length = $key_pair->getKeyLength();
// Save to file
if(!$handle=fopen($baseDir.'data/RSAKey.cnf','w')) exit;
// key length
fwrite($handle,'keyLength='.$keyLength."\n");
// modulo
fwrite($handle,'modulo='.$bcm->bin2int($public_key->getModulus())."\n");
// Public exponent
fwrite($handle,'publicExponent='.$bcm->bin2int($public_key->getExponent())."\n");
// Private exponent
fwrite($handle, 'privateExponent='.$bcm->bin2int($private_key->getExponent())."\n");
fclose($handle);
?>